import org.hamcrest.core.Is;
import org.junit.AfterClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import static org.junit.Assert.assertThat;

public class SuccessfulNavigationCommands {

    @Test
    public void NavigationCommands(){
    WebDriver driver = new FirefoxDriver();
    WebDriverWait wait = new WebDriverWait(driver,10);

    driver.navigate () .to("http://localhost/tracks/login");
    WebElement typeUserName = driver.findElement(By.id("user_login"));
    typeUserName.sendKeys("zyusfe");

    WebElement typeUserPassword = driver.findElement(By.id("user_password"));
    typeUserPassword.sendKeys("zk19881990");

    WebElement clickLoginButton = driver.findElement(By.name("login"));
    clickLoginButton.click();

    wait.until(ExpectedConditions.titleIs("TRACKS::List tasks"));
    WebElement mainMenu= driver.findElement(By.id("navcontainer"));


    //View menu
    WebElement viewMenu = mainMenu.findElement(By.linkText("View"));
    viewMenu.click();

    //
    WebElement clickDoneOnViewMenu = mainMenu.findElement(By.linkText("Calendar"));
    clickDoneOnViewMenu.click();
    new WebDriverWait(driver,5).until(ExpectedConditions.titleIs("TRACKS::Calendar"));

    mainMenu = driver.findElement(By.id("navcontainer"));
    viewMenu = mainMenu.findElement(By.linkText("View"));
    viewMenu.click();
    viewMenu.click();

    WebElement clickOnRepeatingTodos = mainMenu.findElement(By.linkText("Done"));
    clickOnRepeatingTodos.click();
    new WebDriverWait(driver,5).until(ExpectedConditions.visibilityOfElementLocated(By.id("content")));

        mainMenu = driver.findElement(By.id("navcontainer"));
        viewMenu = mainMenu.findElement(By.linkText("View"));
        viewMenu.click();
        viewMenu.click();

        WebElement clickOnFeeds = mainMenu.findElement(By.linkText("Feeds"));
        clickOnFeeds.click();
        new WebDriverWait(driver,5).until(ExpectedConditions.titleIs("TRACKS::Feeds"));


        mainMenu = driver.findElement(By.id("navcontainer"));
        viewMenu = mainMenu.findElement(By.linkText("View"));
        viewMenu.click();
        viewMenu.click();

        WebElement clickOnStatistics = mainMenu.findElement(By.linkText("Statistics"));
        clickOnStatistics.click();
        new WebDriverWait(driver,5).until(ExpectedConditions.titleIs("TRACKS::Statistics"));


    //
    mainMenu = driver.findElement(By.id("navcontainer"));
    WebElement starredMenu = mainMenu.findElement(By.linkText("Starred"));
    starredMenu.click();
    new WebDriverWait(driver,5).until(ExpectedConditions.titleIs("TRACKS::Tagged with 'starred'"));
    //
    mainMenu = driver.findElement(By.id("navcontainer"));
    WebElement ProjectMenu = mainMenu.findElement(By.linkText("Projects"));
    ProjectMenu.click();
    new WebDriverWait(driver,5).until(ExpectedConditions.titleIs("TRACKS::List Projects"));

    mainMenu = driver.findElement(By.id("navcontainer"));
    WebElement ticklerMenu = mainMenu.findElement(By.linkText("Tickler"));
    ticklerMenu.click();
    new WebDriverWait(driver,5).until(ExpectedConditions.titleIs("TRACKS::Tickler"));

    // Organize menu
    mainMenu = driver.findElement(By.id("navcontainer"));
    WebElement organizeMenu = mainMenu.findElement(By.linkText("Organize"));
    organizeMenu.click();

    WebElement clickOnContext = mainMenu.findElement(By.linkText("Contexts"));
    clickOnContext.click();
    new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::List Contexts"));

    //
    mainMenu = driver.findElement(By.id("navcontainer"));
    organizeMenu = mainMenu.findElement(By.linkText("Organize"));
    organizeMenu.click();

    WebElement clickOnNotes = mainMenu.findElement(By.linkText("Notes"));
    clickOnNotes.click();
    new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::All notes"));

    mainMenu = driver.findElement(By.id("navcontainer"));
    organizeMenu = mainMenu.findElement(By.linkText("Organize"));
    organizeMenu.click();
    organizeMenu.click();
    WebElement clickOnReview = mainMenu.findElement(By.linkText("Review"));
    clickOnReview.click();
    new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::Review"));

    mainMenu = driver.findElement(By.id("navcontainer"));
    organizeMenu = mainMenu.findElement(By.linkText("Organize"));
    organizeMenu.click();
    organizeMenu.click();
    WebElement clickOnRepeatingTodo = mainMenu.findElement(By.linkText("Repeating todos"));
    clickOnRepeatingTodo.click();
    new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::Recurring Actions"));

    mainMenu = driver.findElement(By.id("navcontainer"));
    WebElement clickOnAdmin = mainMenu.findElement(By.linkText("Admin"));
    clickOnAdmin.click();
    clickOnAdmin.click();
    WebElement clickPreferences = mainMenu.findElement(By.linkText("Preferences"));
    clickPreferences.click();
    new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::Preferences"));

    mainMenu = driver.findElement(By.id("navcontainer"));
    clickOnAdmin = mainMenu.findElement(By.linkText("Admin"));
    clickOnAdmin.click();
    clickOnAdmin.click();
    WebElement clickOnExport = mainMenu.findElement(By.linkText("Export"));
    clickOnExport.click();
    new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::Export"));

        mainMenu = driver.findElement(By.id("navcontainer"));
        clickOnAdmin = mainMenu.findElement(By.linkText("Admin"));
        clickOnAdmin.click();
        clickOnAdmin.click();
        WebElement manageUsers = mainMenu.findElement(By.linkText("Manage users"));
        manageUsers.click();
        new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::Manage Users"));


        mainMenu = driver.findElement(By.id("navcontainer"));
        WebElement helpMenu = mainMenu.findElement(By.linkText("?"));
        helpMenu.click();
        helpMenu.click();

        WebElement integrateTracks = mainMenu.findElement(By.linkText("Integrate Tracks"));
        integrateTracks.click();
        new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::Integrations"));

        mainMenu = driver.findElement(By.id("navcontainer"));
        helpMenu = mainMenu.findElement(By.linkText("?"));
        helpMenu.click();
        helpMenu.click();

        WebElement clickOnRestDocumentation = mainMenu.findElement(By.linkText("REST API Docs"));
        clickOnRestDocumentation.click();
        new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::REST API Documentation"));

        mainMenu = driver.findElement(By.id("navcontainer"));
        WebElement clickHomeMenu = mainMenu.findElement(By.linkText("Home"));
        clickHomeMenu.click();

     new WebDriverWait(driver,10).until(ExpectedConditions.titleIs("TRACKS::List tasks"));



            driver.close();
            driver.quit();
        }
    }








